var app = getApp()
var modal = require('../../utils/modal');
var request = require('../../utils/request');
var pay = require('../../utils/pay');
var utils = require('../../utils/utils');
var mock = require('../../mock/mock');
var addrMock = require('../../mock/addrPicker');
var swiper = require('../../components/swiper/swiper');
var sliderBar = require('../../components/sliderBar/sliderBar');
var sliderPanel = require('../../components/sliderPanel/sliderPanel');

var counter = require('../../components/counter/counter');

var addrPicker = require('../../components/addrPicker/addrPicker');
var selfActionSheet = require('../../components/actionSheet/actionSheet');
var storage = require('../../utils/storage');
// var storage = require('../../utils/storage');
// storage.set('name','zhangsan');
// storage.remove('name');
// console.log(storage.get('name'));
var shareContent = {
    'title':'企鹅优品-优质生活指南',
    'desc':'腾讯精品体验平台，为用户提供优质的生活方式和购物体验。',
    'path':'/pages/project-index/index'
}
var share = utils.share(shareContent);
var pageSetting = {
    callback:function(componentName){
        // console.log(componentName);
        switch(componentName){
            case 'sliderBar':
                var type = arguments[1];
                var id = arguments[2];  
                this.setData({
                    wiiSliderBar:{
                        isActive:id,
                        data:this.data['wiiSliderBar']['data']
                    }
                });
            break;
            case 'sliderPanel':
                var current = arguments[1];
                wx.previewImage({
                    current: current,
                    urls: mock.imageList
                });
            break;
            case 'actionSheet':
                //actionSheet提交
                console.log('商品id:'+this.data['wiiActionSheet']['data']['id']);
                console.log('购买数量:'+this.data['wiiActionSheet']['data']['counter']['countNumber']);
                console.log('选择类型:');
                console.log(this.data['wiiActionSheet']['data']['choosedSku']);
            break;
            case 'actionSheetTap':
                //actionSheet点击
                console.log('点击选择的类型:');
                console.log(this.data['wiiActionSheet']['data']['choosedSku']);
            break;
            case 'counterTap':
                var countNum = arguments[1];
                console.log("数量" + countNum);
            break;
            default:
            break;
        }
    },
    data: {
        lists:[{},{},{}]
    },
    onLoad: function(options) {
        app.getSystemInfo(function(res){
            console.log(res);
        });
        app.getNetworkType(function(res){
            console.log(res);
        });
        /*为组件填充数据*/
        var tempSwiper = this.data['wiiSwiper'];
        tempSwiper['data'] = mock.list;

        var tempSliderBar = this.data['wiiSliderBar'];
        tempSliderBar['data'] = mock.navs;
        
        var tempSliderPanel = this.data['wiiSliderPanel'];
        tempSliderPanel['data'] = mock.list;
        // console.log(tempSliderPanel)

        var tempAddrPicker = this.data['wiiAddrPicker'];
        tempAddrPicker['data'] =  addrMock.list;
        // console.log(tempAddrPicker)

        var tempCounter = this.data['wiiCounter'];
        tempCounter['data'] =  mock.counter;
        // console.log('-----counter-----')
        // console.log(tempCounter)
        // tempAddrPicker['addr'] = addrMock.addr;

        //自定义actionSheet
        var tempActionSheet = this.data['wiiActionSheet'];
        tempActionSheet['data'] =  mock.actionSheet;
    
        this.setData({
            wiiSliderBar:tempSliderBar,
            wiiSliderPanel:tempSliderPanel,
            wiiSwiper:tempSwiper,
            wiiAddrPicker:tempAddrPicker,
            wiiCounter:tempCounter,
            wiiActionSheet:tempActionSheet
        });
        console.log('-----data-----')
        console.log(this.data);
        
        // request.post('/auto/car/get_brand_list',{'wx_open_id':storage.get('openId')})
        //     .then(function(res){
        //         modal.toast('请求成功！');
        //     });
        this.setData({
            'wiiSliderBar.data':mock.navs,
            'wiiSliderPanel.data':mock.list,
            'wiiSwiper.data':mock.list,
            'wiiShare.data.title':'ddd'
        });
        console.log(storage.get('openId'))
        

    },
    onPullDownRefresh(){
        modal.loading();
        setTimeout(function(){
            wx.stopPullDownRefresh();
            modal.hide();
        },1500);
    },
    showLoading:function(){
        modal.loading();
        setTimeout(function(){
            modal.hide();
        },2000);
    },
    showToast:function(){
        modal.toast('123123','提示',function(){
            console.log('确定');
        });
    },
    showConfrim:function(){
        modal.confirm('123','456',function(res){
            if(res==1){
                
            }
        });
    },
    showActionSheet:function(){
        wx.showActionSheet({
            itemList: ['确定','再看看','试一下呗'],
            success: function(res){
                if (!res.cancel) {
                    modal.toast(('选择了'+res.tapIndex),'提示',function(){
                        console.log('选择');
                    });
                }else{
                    modal.toast('已取消','提示',function(){
                        console.log('取消');
                    });
                }
            }
        });
    },
    showSelfActionSheet:function(){
        //显示actionSheet
        this.wiiShowActionSheet();
    },
    wiiTabChange:function(evt){
        var tabId = evt.target.dataset.id;
        this.setData({
            wiiTab:{
                active:tabId
            }
        });
    },
    callwxPay:function(){
        pay.callPay({
            "order_id":137819947401,
            "success":function(res){console.log(res)},
            "fail":function(res){console.log(res)}}
        );
    }
};

var addrPickerOption = {
    data:{
        wiiAddrPicker:{
            'addrPickerUrl':'/wxapp_api/api',
            'addrPickerKey':{
                'setDefault':'self:uc_api:address:setDefault',
                'delAddr':'self:uc_api:address:del',
                'getAddrList':'self:uc_api:address:get',
                'addAddr':'self:uc_api:address:add'
            }
        }
    }
};

utils.assign(pageSetting,share,sliderBar,sliderPanel,swiper,addrPicker,addrPickerOption,counter,selfActionSheet);
Page(pageSetting);
